{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Running the PopSyCLE pipeline with run.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/michael/miniconda3/lib/python3.6/site-packages/pysynphot/locations.py:346: UserWarning: Extinction files not found in /Users/michael/models/cdbs/extinction\n",
      "  warnings.warn('Extinction files not found in %s' % (extdir, ))\n"
     ]
    }
   ],
   "source": [
    "from popsycle import run"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The entire PopSyCLE pipeline can be run with `popsycle/run.py`. \n",
    "\n",
    "First, create a PopSyCLE configuration file that contains the parameters necessary to run the PopSyCLE pipeline. You may want to create a single PopSyCLE configuration file for each project in order to keep the execution of PopSyCLE the same over multiple\n",
    "fields. An example can be found in `popsycle/data/popsycle_config.yaml` and a custom popsycle config file can be generated using ``popsycle.run.generate_popsycle_config_file``."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "run.generate_popsycle_config_file(config_filename='popsycle_config.yaml',\n",
    "                                  radius_cut=2,\n",
    "                                  obs_time=1095,\n",
    "                                  n_obs=10,\n",
    "                                  theta_frac=2,\n",
    "                                  blend_rad=0.75,\n",
    "                                  isochrones_dir='/Users/myself/popsycle_isochrones',\n",
    "                                  bin_edges_number=None,\n",
    "                                  BH_kick_speed_mean=50,\n",
    "                                  NS_kick_speed_mean=400,\n",
    "                                  photometric_system='ubv',\n",
    "                                  filter_name='R',\n",
    "                                  red_law='Schlafly11')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Second, create a field configuration file that contains the galactic longitude and latitude that you would like to conduct the survey and the area over which the survey should be conducted. This can be dong using `popsycle.run.generate_field_config_file`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "run.generate_field_config_file(config_filename='field_config.yaml',\n",
    "                               longitude = 1.25,\n",
    "                               latitude = -2.65,\n",
    "                               area=0.001)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`popsycle/run.py` can be run from the command line with:\n",
    "\n",
    "```python {PATH_TO_POPSYCLE}/popsycle/run.py \n",
    "                   --output-root=test \n",
    "                   --field-config-filename=field_config.yaml \n",
    "                   --popsycle-config-filename=popsycle_config.yaml \n",
    "                   --n-cores-calc-events=2 \n",
    "                   --seed=0 \n",
    "                   --overwrite```\n",
    "                   \n",
    "This command will execute the PopSyCLE pipeline in your current directory, following all of the steps outlined in `popsycle/docs/PopSyCLE_example.ipynb`."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "source": [],
    "metadata": {
     "collapsed": false
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}